class Solution:
    def longestMountain(self, arr: list) -> int:
        up, down, maxLen = 0, 0, 0
        for i in range(1, len(arr)):
            if (down and arr[i-1] < arr[i]) or arr[i-1] == arr[i]:
                up, down = 0, 0
            if arr[i-1] < arr[i]:
                up += 1
            if arr[i-1] > arr[i]:
                down += 1
            if up > 0 and down > 0:
                maxLen = max(maxLen, up+down+1)

        return maxLen
